<template>
	<view class="page">
		<view class="status_bar"></view>
		<view class="top">
			<image src="../../static/icon/icon_back.png" @tap="toBack"></image>
		</view>
		<view class="content">
			<!-- <image class="jixianwu" src="../../static/icon/login_jixianwu.png"></image> -->
			<image class="loginBg" src="../../static/icon/login_bg.png"></image>
			<view class="title">
				<image src="../../static/icon/logo.png"></image>
				<view class="name">
					<view class="text">拼乐惠</view>
					<view class="pinyin">PINLEHUI</view>
				</view>
			</view>
		<!-- 	<view class="tip">欢迎回来！登录到您的账户</view> -->
			<view class="inputBox">
				<view class="phonetip">手机号码</view>
				<view class="phone">
					<view class="left" >
						<view class="text">+{{zone}}</view>
						<image src="../../static/icon/phoneDown.png"></image>
					</view>
					<input class="right" v-model="phone" placeholder="请输入手机号" />
				</view>
				<view class="passdword">
					<input v-model="pwd" placeholder="请输入密码" :password="pwdStatus" />
					<image @click="changeStatus" v-show="!pwdStatus" src="../../static/icon/icon_pwd_open@3x.png"></image>
					<image @click="changeStatus" v-show="pwdStatus" src="../../static/icon/icon_pwd_close@3x.png"></image>
				</view>
			</view>
			<!-- <view class="forget" @tap="toForGet">忘记密码？</view> -->
			<button class="btn" :loading="isLoading" :disabled="isLoading" @click="toLogin">登录</button>
			<view class="bottom">
				<view class="regiter" @tap="toRegister">立即注册</view>
				<view class="forget" @tap="toForGet">忘记密码</view>
			</view>
		</view>
		<mpvue-picker :themeColor="themeColor" ref="mpvuePicker" :mode="mode" :pickerValueDefault="pickerValueDefault"
		 @onConfirm="onConfirm" :pickerValueArray="pickerValueArray"></mpvue-picker>
	</view>
</template>

<script>
	import mpvuePicker from '../../components/mpvue-picker/mpvuePicker.vue';
	import {tokenLogin} from '../../api/login/index'
	import {version} from '../../config/index'
	export default {
		components: {
			mpvuePicker
		},
		data() {
			return {
				zone: '86',
				phone: "",
				pwd: "",
				version:version,
				pwdStatus: true,
				isLoading:false,
				textValue: "选择积分类型",
				typeId: '',
				type:null,
				mode: 'selector',
				pickerValueArray: [],
				pickerValueDefault: [0],
				coin: 0,
				themeColor: "#FE2625",
			}
		},
		onLoad() {

		},
		methods: {
			toBack() {
				uni.switchTab({
					url:'/pages/index/index'
				})
			},
			toRegister() {
				uni.navigateTo({
					url: './register'
				})
			},
			toForGet() {
				uni.navigateTo({
					url: './forget'
				})
			},
			changeStatus() {
				this.pwdStatus = !this.pwdStatus
			},
			toLogin() {
				if (this.phone == '') {
					this.$tools.toast("请输入用户名")
					return
				}
				if (this.pwd == '') {
					this.$tools.toast("请输入密码")
					return
				}
				this.isLoading = true
				const res = uni.getSystemInfoSync();
				if (res.platform == 'android') {
					this.type = 0
				} else if (res.platform == 'ios') {
					this.type = 1
				}
				tokenLogin({
					phone: this.phone,
					password: this.pwd,
					version: this.version,
					type:this.type
				}).then(res => {
					this.isLoading = false
					uni.setStorageSync('token',res.data.obj.token)
					uni.setStorageSync('userCode',res.data.obj.userCode)
					uni.setStorageSync('inviteCode',res.data.obj.inviteCode)
					uni.showToast({
						title:"登录成功",
						icon:'none'
					})
					uni.switchTab({
						url:'/pages/index/index'
					})
				}).catch(err => {
                    this.isLoading = false
				})
			},
			getZone() {
				this.$request("Post", "/ajax/zoneList").then(res => {
					for (var i = 0; i < res.obj.length; i++) {
						let obj = {}
						obj.label = res.obj[i].cnName
						obj.value = res.obj[i].zone
						this.pickerValueArray.push(obj)
					}
				})
			},
			selectZone() {
				this.$refs.mpvuePicker.show();
			},
			onConfirm(e) {
				if (this.pickerValueArray.length == 0) {
					return
				}
				this.zone = e.value[0]
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: $uni-bg-color;
		z-index: 99;
	}

	.top {
		padding: 30rpx;
		text-align: left;

		image {
			width: 40rpx;
			height: 40rpx;
		}
	}

	.content {
		background: #FFFFFF;
		margin: 0 60rpx;
		margin-top: 250rpx;
		border-radius: 30rpx;
		padding: 30rpx;
		position: relative;
        .jixianwu{
			width: 150rpx;
			height: 200rpx;
			position: absolute;
			top: -200rpx;
			left: 50%;
			margin-left: -75rpx;
		}
		.loginBg{
			width: 380rpx;
			height: 272rpx;
			position: absolute;
			top: -272rpx;
			left: 50%;
			margin-left: -190rpx;
		}
		.title {
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 100rpx;
				height: 100rpx;
			}

			.name {
				margin-left: 15rpx;
				.text{
					font-size: 45rpx;
					
				}
				.pinyin{
					text-align: center;
					font-size: 28rpx;
				}
			}
		}

		input {
			font-size: 27rpx !important;
		}

		.inputBox {
			margin-top: 80rpx;

			.phonetip {
				font-size: 21rpx;
				color: #808080;
			}

			.phone {
				display: flex;
				justify-content: left;
				align-items: center;
				padding: 30rpx 0;
				border-bottom: 0.5px solid $uni-border-color;

				.left {
					flex: none;
					display: flex;
					justify-content: left;
					align-items: center;
					padding-left: 8rpx;
					padding-right: 10rpx;
					border-right: 0.5px solid $uni-border-color;
					margin-right: 30rpx;

					.text {
						font-size: 28rpx;
						align-self: center;
						line-height: 30rpx;
					}

					image {
						width: 22rpx;
						height: 22rpx;
						align-self: center;
						margin: 0 10rpx;
					}
				}

				.right {
					flex: auto;
					padding: 5rpx;
				}

			}

			.passdword {
				margin-top: 30rpx;
				padding: 30rpx 0;
				border-bottom: 0.5px solid $uni-border-color;
				display: flex;
				align-items: center;

				input {
					flex: auto;
					padding: 5rpx;
				}

				image {
					flex: none;
					width: 40rpx;
					height: 40rpx;
				}
			}
		}

		// .forget{
		// 	margin-top: 60rpx;
		// 	font-size: 22rpx;
		// 	color: #808080;               }
		.btn {
			background: $uni-bg-color;
			height: 90rpx;
			line-height: 90rpx;
			color: #FFFFFF;
			margin-top: 60rpx;
		}

		.bottom {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 130rpx;
			font-size: 26rpx;
			padding: 0 20rpx;
		}
	}
</style>
